package com.skillworld.webapp.model.department.rank;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.skillworld.webapp.model.user.User;
import com.skillworld.webapp.model.util.dao.GenericDaoHibernate;

@Repository("LevelDepartmentDao")
public class DeptRankDaoHibernate extends GenericDaoHibernate<DeptRank,Long> implements DeptRankDao {
    
    @SuppressWarnings("unchecked")
    public List<User> findNewDepartmentLeaders(Long deptId, int count){
        
        return(List<User>) getSession().createQuery(
                "SELECT dr.user FROM DeptRank dr " +
                "where dr.department.departmentId = :deptId " +
                "order by dr.level desc, dr.points desc")
                .setParameter("deptId", deptId)
                .setFirstResult(0)
                .setMaxResults(count)
                .list();
    }
    
    public long numberOfUsersInDepartment(Long deptId){
        
        return  (Long) getSession().createQuery(
                "SELECT count(dr.user) FROM DeptRank as dr " +
                "where dr.department.departmentId = :deptId")
                .setParameter("deptId", deptId)
                .uniqueResult();
    }
}
